'Demonstration of SPI bus on the PIC18X, to control the PGA2310 

symbol	mute			= 0
symbol	SDI  			= 1
symbol	SDO  			= 2
symbol	CS	  		= 3 
symbol	SCL 			= 4
symbol	dB_Level	        = b2

Main:
let pins = %00001000		'Pull CS high for its normal state

pause 100			'Allow time for PGA2310 to power up
gosub config_SPI
high mute			'Turn PGA2310 mute off
let dB_Level = 0

up_loop:
let dB_Level = dB_Level + 1
gosub Transmit
if dB_Level != 255 then up_loop	'Before this point you can read the SSPBUF register to comfirm change

down_loop:
let dB_Level = dB_Level - 1
gosub Transmit
if dB_Level != 0 then down_loop
goto up_loop
end

config_SPI:
let b0 = 32			'00100000	'14h_SSPCON SPI enable'
let b1 = 192 			'11000000	'94h_SSPSTAT clock edge select'
poke $14,b0
poke $94,b1		
return

Transmit:	
low CS				'Pull CS low to enable the data read on the PGA2310
poke $13,dB_Level		'Write data to the SSPBUF to execute SPI bus transfer-Right channel, 8bits
poke $13,dB_Level		'Write data to the SSPBUF to execute SPI bus transfer-Left channel, 8bits
high CS				'Pull CS high to stop communication
pause 400			'used only for testing to slow the volume change
return